package br.edu.universo.si.projeto2.infojob.client.componentes;

import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * COMPONENTE - Campo de E-Mail
 * @author Andrey A. de Oliveira
 * @since 21/09/2008
 */
public class EMailBox extends TextBox
{
	public EMailBox()
	{
		this.setWidth("200px");
		this.setMaxLength(40);
		
		this.addKeyboardListener(
			new KeyboardListener()
			{
				public void onKeyPress(Widget sender, char keyCode, int modifiers)
				{
					if (keyCode == ' ') // nao permite inserir espaco vazio
					{
						((TextBox) sender).cancelKey();
					}
				}

				// implementacao vazia
				public void onKeyDown(Widget sender, char keyCode, int modifiers) { };
				public void onKeyUp(Widget sender, char keyCode, int modifiers) { };
			}
		);
		
	}
	
	/**
	 * Verifica se o campo esta vazio ou nao
	 */
	public boolean isVazio()
	{
		if (EMailBox.this.getText().equalsIgnoreCase(""))
		{
			return true;
		}

		return false;
	}
	
	/**
	 * Verifica se o e-mail inserido eh valido
	 */
	public boolean isEMailValido()
	{
		if (EMailBox.this.getText().indexOf("@") == -1)
		{
			return false;
		}

		if (EMailBox.this.getText().indexOf(".") == -1)
		{
			return false;
		}

		return true;
	}
}